﻿
 //以下为自定义方法，validate方法中没有的
 //判断两个值是否相等
 jQuery.validator.addMethod("notEqualTo", function(value, element, param) {
     return value != $(param).val();
 }, $.validator.format("两次输入不能相同!"));
    
 //只能输入数字
 jQuery.validator.addMethod("isNum", function(value, element) {
  var RegExp = /^\d+$/;
     return RegExp.test(value);
 }, $.validator.format("只能为数字!"));
    
 //电话号码验证
 jQuery.validator.addMethod("isTell", function(value, element) {
  var RegExp = /^(\d{3}-(\d{8})|(\d{7}))$|^(\d+)$|^(\d{4}-(\d{7})|(\d{8}))$|^(\d{7,8})$/;
     return RegExp.test(value);
    }, $.validator.format("电话号码输入不正确!"));
 
  // 身份证号码验证     
 jQuery.validator.addMethod("idcardno", function(value, element) {  
   return this.optional(element) || isIdCardNo(value);     
 }, "请正确输入身份证号码");  
   
 //页面加载时调用
    $(function() {
        $('#form1').validate({
            rules: {
            txtCompanyName: {
                    required: true,
                    maxlength: 50,
                    minlength: 4 
                },
                  txtAddress: {
                    required: true,
                },
                 txtCurrentIntegral: {
                    required: true,
                    isNum: true
                },
                txtGuardLine: {
                      required: true,
                    isNum: true 
                },
                txtxStatisticalStartDate: {
                    required: true,
                   date: true
                },
                 txtStatisticalEndDate: {
                    required: true,
                   date: true
                },
                txtUserName: {
                    required: true,
                    maxlength: 18,
                    minlength: 4
                },
                txtUserPwd: {
                    required: true,
                    maxlength: 18,
                    minlength: 6,
                    notEqualTo:"#txtUserPwd"
                },
                txtRUserPwd: {
                    required: true,
                    equalTo: "#txtUserPwd"
                },
                txtAddress: {
                    required: true,
                    maxlength: 50
                },
                txtUrl: {
                    required: true,
                    url: true
                },
                txtPhone: {
                   
                    minlength: 7,
                    maxlength: 13,
                    isTell: true
                },
                txtZipCode: {
                    required: true,
                    minlength: 6,
                    maxlength: 6,
                    isNum: true
                },
                txtEmail: {
                     
                    email: true,
                    maxlength: 40
                },
                txtIDCard{
                 
                 idcardno:true
                },
                 txtAutoDeductPeriod{
                 
                 isNum:true
                },
                 txtAutoDeductPoints{
                 
                 isNum:true
                }
            },
            messages: {
            txtCompanyName: {
                    required: "公司名称不能为空！",
                    maxlength: "最长为50个字符！",
                    minlength: "最短为4个字符！" 
                },
                  txtAddress: {
                    required: "地址不能为空！" 
                },
                 txtCurrentIntegral: {
                    required: "积分不能为空！",
                    isNum: "请输入合法数字！" 
                },
                txtGuardLine: {
                    required: "警戒线不能为空！",
                    isNum: "请输入合法数字！" 
                },
                txtxStatisticalStartDate: {
                    required: "统计开始时间不能为空！",
                   date: "请输入合法的日期"
                },
                 txtStatisticalEndDate: {
                    required: "统计结束时间不能为空！",
                   date: "请输入合法的日期" 
                },
                txtUserName: {
                    required: "用户名不能为空！",
                    maxlength: "最长为18个字符！",
                    minlength: "最短为4个字符！"
                },
                txtUserPwd: {
                    required: "密码不能为空！",
                    maxlength: "最长为18个字符！",
                    minlength: "最短为6个字符！",
                    notEqualTo: "用户名和密码不能相同！"
                },
                txtRUserPwd: {
                    required: "密码不能为空！",
                    equalTo: "两次输入密码不相同！"
                },
                 
                txtUrl: {
                    required: "网址不能为空！",
                    url: "请填写正确的网址！"
                },
                
                txtZipCode: {
                    required: "邮编不能为空！",
                    minlength: "邮编为6个数字！",
                    maxlength: "邮编为6个数字！",
                    isNum: "请输入数字！"
                }  
                 
            },
            errorPlacement: function(error, element) {
                error.appendTo(element.parent());
            },
            submitHandler: function(form) {
                form.submit();
            },
            errorClass: "error",
 //           focusCleanup: true, //被验证的元素获得焦点时移除错误信息
            success: function(label) {
                label.html("<span style=\"color:green\">填写正确！</span>").addClass("success");
            }
        });
 
 
    });